#ifndef __UTIL_CMD_H
#define __UTIL_CMD_H

#include "stdint.h"

/* If dynamic memory allocation is used, there is no limit to the number of commands and parameters.
 * But you need to provide functions for memory allocation and relclamation. */
#define CMD_CONFIG_DYNAMIC_MEMORY_EN    0

#if CMD_CONFIG_DYNAMIC_MEMORY_EN
    #include "stdlib.h"
    #define CmdMalloc   malloc
    #define CmdFree     free
#else
    #define CMD_ARRAY_SIZE_MAX  16
    #define CMD_PARAM_MAX       16
#endif

typedef struct __CmdSubCmd {
    char *name;
    uint16_t index;
#if CMD_CONFIG_DYNAMIC_MEMORY_EN
	struct __CmdSubCmd *next;
#endif
} CmdParamTypeDef;

typedef void (* CmdCallback)(CmdParamTypeDef *param);

void CmdInit(void);
int8_t CmdAppend(char *name, CmdCallback callBack);
int8_t CmdDelete(char *name);
int8_t CmdAppendParam(char *cmdName, char *param);
int8_t CmdDeleteParam(char *cmdName, char *parName);
void CmdCheck(char *str);

void CmdShow(void);

#endif
